﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

using System.IO.Ports;
using Safover.LidarCollector.Core;
using Safover.LidarCollector.Models;

namespace Ec.Bewis
{
    public class VirtualBewisElectronicCompass : ElectronicCompass
    {
        #region Singleton
        public static ElectronicCompass Instance { get; } = new VirtualBewisElectronicCompass();

        private VirtualBewisElectronicCompass()
        {
            // 默认值
            RollAngle = 0;
            HeadingAngle = 0;
            PitchAngle = 0;
        }

        #endregion
        bool IsOpen { get; set; }

        public override string DeviceType => "VirtualBewisElectronicCompass";

        public override bool IsSerialPortOpen => IsOpen;

        protected override void OnDataReceived(object sender, SerialDataReceivedEventArgs e)
        {
        }

        protected override void DoOpenSerialPort()
        {
            IsOpen = true;
        }

        protected override bool DoCloseSerialPort()
        {
            IsOpen = false;
            return true;
        }

        public override ElectronicCompassAngles? QueryAngles()
        {
            DeviceReadingsUpdated?.Invoke(this, new ElectronicCompassReadingsUpdatedEventArgs
            {
                RollAngle = (float)RollAngle,
                HeadingAngle = (float)HeadingAngle,
                PitchAngle = (float)PitchAngle,
            });

            return new ElectronicCompassAngles
            {
                RollAngle = (float)RollAngle,
                HeadingAngle = (float)HeadingAngle,
                PitchAngle = (float)PitchAngle,
            };
        }
    }
}
